/*
 *
 *方法的整理与重构
 *
 *
 */

//定义app参数名称，并加载其它模块
var authApp=angular.module('authapp', ["ngCookies",'ngFileUpload','ui.bootstrap']);

//此为定位页面所用
authApp.value('page','interviewList');

/*controller部分*/

//主要操作controller
authApp.controller("opinionEditController",function($scope,$http,$getQueryString,$timeout,$sce){
    $scope.schoolId = $getQueryString("schoolId");
    $scope.schoolName = decodeURIComponent(decodeURIComponent($getQueryString("schoolName")));
    
    $scope.sign = $getQueryString("sign");
    $scope.state = $getQueryString("state");
    $scope.f = parseInt($getQueryString("f"));
    $scope.pid = $getQueryString('pid')
    var pid = null
    var queryMainApi=apis.queryOneIA;
    var requestJson={'schoolId':$scope.schoolId,'sign':decodeURIComponent($scope.sign)};
    $scope.queryMain=function(){
        $http({
            method:'post',
            url:queryMainApi,
            data:requestJson,
        }).success(function(response){
            if(response.code=="000000"){
                $scope.kind = response.data.kind;
                pid = response.data.pid
                $scope.reportingTime = response.data.reportingTime;
                $scope.identity1 = response.data.identity1;
                $scope.interview1 = response.data.interview1;
                $scope.dept1 = response.data.dept1;
                $scope.identity2 = response.data.identity2;
                $scope.interview2 = response.data.interview2;
                $scope.dept2 = response.data.dept2;
                $scope.identity3 = response.data.identity3;
                $scope.interview3 = response.data.interview3;
                $scope.dept3 = response.data.dept3;
                $scope.suggest = response.data.suggest;
            }else{
                alert(response.errorMsg);
            }
        }).error(function(){
            alert("网络出现故障，请确认网络是否连接");
        })
    }
    $scope.queryMain();

    $scope.upadteData = function() {
        
        if(window.confirm("是否确认保存？")){
            var requestJson={
                'pid': pid,
                'kind':$scope.kind,
                'reportingTime':$scope.reportingTime,
                'talkCourse':$scope.talkCourse,
                'courseName':$scope.courseName,
                'technicalTitle':$scope.technicalTitle,
                'post':$scope.post,
                'talkCourseContent':$scope.talkCourseContent,
                'generalComment':$scope.generalComment,
                'suggest':$scope.suggest};
            $http({
                method:'post',
                url:apis.updateInterviewAnalyse,
                data:requestJson,
            }).success(function(response){
                if(response.code=="000000"){
                    alert("保存成功！");
                    $scope.state = '1';
                    $scope.queryMain();
                }else{
                    alert(response.errorMsg);
                }
            }).error(function(){
                alert("网络出现故障，请确认网络是否连接");
            })
        }  
    }
    $scope.down=function() {
        return window.open('/views/investiga/table9.html?schoolId='+ $scope.schoolId+'&schoolName='+ encodeURIComponent($getQueryString("schoolName")) + '&sign=' + $scope.sign + '&state='+ $scope.state + '&f='+$scope.f+'&pid='+ $scope.pid)
    }
    //保存
    $scope.saveData=function(){
       /* String schoolId = map.get("schoolId");//学校id
        String kind = map.get("kind");//参评类别
        String sign = map.get("sign");
        String reportingTime = map.get("reportingTime");//申报时间
        String identity1 = map.get("identity1");//身份1
        String interview1 = map.get("interview1");//访谈重点1
        String identity2 = map.get("identity2");//身份2
        String interview2 = map.get("interview2");//访谈重点2
        String identity3 = map.get("identity3");//身份3
        String interview3 = map.get("interview3");//访谈重点3
        String suggest = map.get("suggest");//建议*/
        if(window.confirm("是否确认保存？")){
            var requestJson={
                'schoolId':$scope.schoolId,
                'kind':decodeURI($scope.kind),
                'sign': $scope.sign,
                'reportingTime':decodeURI($scope.reportingTime),
                'identity1':decodeURI($scope.identity1),
                'interview1':decodeURI($scope.interview1),
                'dept1':decodeURI($scope.dept1),
                'identity2':decodeURI($scope.identity2),
                'interview2':decodeURI($scope.interview2),
                'dept2':decodeURI($scope.dept2),
                'identity3':decodeURI($scope.identity3),
                'interview3':decodeURI($scope.interview3),
                'dept3':decodeURI($scope.dept3),
                'suggest':decodeURI($scope.suggest)};
            $http({
                method:'post',
                url:apis.saveInterviewAnalyse,
                data:requestJson,
            }).success(function(response){
                if(response.code=="000000"){
                    alert("保存成功！");
                    $scope.state = '1';
                    $scope.queryMain();
                }else{
                    alert(response.errorMsg);
                }
            }).error(function(){
                alert("网络出现故障，请确认网络是否连接");
            })
        }
    }


    //返回到前页面
    $scope.goback=function(){
        //if(window.confirm("是否确认返回？")){
        javascript:history.back(-1);
        //}
    }
    function unUnicode(str)
    {
        return unescape(str.replace(/\\/g, "%"));
    }

})

function toUnicode(str)
    {
        return escape(str).replace(/%/g,"\\").toLowerCase();
    }